<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/ajax2.js"></script>

</head>

<body>
    <button>获取XML数据的格式</button>

    <script>
        const btnObj = document.querySelector("button")
        btnObj.onclick = function () {
            ajax({
                url: 'http://www.biwuit.cn/spboot/xmlFormat',
                success: function (data,xmlHttpRequest) {
                    /* 
                        <students>
                            <student>
                                <sid>001</sid>
                                <name>张三</name>
                            </student>
                            <student>
                                <sid>002</sid>
                                <name>王二丫</name>
                            </student>
                        </students>
                    */
                    //xml格式的数据

                    //data返回的是字符串，不方便解析
                    console.log(data)
                    //返回的是文档对象
                    console.log(xmlHttpRequest.responseXML)
                    const xmlObj = xmlHttpRequest.responseXML;
                    const stu1 = xmlObj.querySelector("student")
                    //文本才有node，现在是元素
                    console.log(stu1.querySelector("name").nodeValue)   //null
                    console.log(stu1.querySelector("name").innerHTML)
                    /* 
                        总结：操作xml标签，就跟操作html标签是一样的
                    */
                }
            })
        }
    </script>
</body>

</html>